package com.itheima.controller;

import com.itheima.service.SysDictDataService;
import com.itheima.utils.Result;
import com.itheima.utils.StatusCode;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sysDictData")
public class SysDictDataController {

    @Resource
    private SysDictDataService sysDictDataService;

    /**
     * 根据字典类型获取字典数据
     *
     * @Param dictType
     */
    @PostMapping("/getListByDictType")
    public Result getListByDictType(@RequestParam String dictType) {
        Map<String,Object> map = sysDictDataService.getMapByDictType(dictType);
        return new Result<>(StatusCode.SUCCESS, map);
    }

    /**
     * 根据字典类型获取字典数据
     *
     * @Param dictType
     */
    @PostMapping("/getListByDictTypeList")
    public Result getListByDictTypeList(@RequestBody List<String> dictTypeList) {
        Map<String,Object> resultMap = new HashMap<>();
        if(dictTypeList != null && dictTypeList.size()>0){
            for (String dictType : dictTypeList) {
                Map<String,Object> map = sysDictDataService.getMapByDictType(dictType);
                resultMap.put(dictType,map);
            }
        }
        return new Result<>(StatusCode.SUCCESS, resultMap);
    }
}
